//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ft.adbix.core.view.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Build.VERSION;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ft.adbix.core.R;
import com.ft.adbix.core.listener.CusClickListener;
import com.ft.adbix.utils.ShopAppUtil;


public class WebViewActivity extends Activity {
    private WebView webView;
    protected ProgressBar progressBar;

    public WebViewActivity() {
    }

    public static void openUrl(@NonNull Context context, @NonNull String url, @NonNull String title, boolean isLandScape) {
        Intent intent;
        if (isLandScape) {
            intent = new Intent(context, LandscapeWebViewActivity.class);
        } else {
            intent = new Intent(context, WebViewActivity.class);
        }

        intent.putExtra("KEY_WEB_URL", url);
        intent.putExtra("KEY_WEB_TITLE", title);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void openHtml(@NonNull Context context, @NonNull String html, @NonNull String title) {
        Intent intent = new Intent(context, WebViewActivity.class);
        intent.putExtra("KEY_WEB_HTML", html);
        intent.putExtra("KEY_WEB_TITLE", title);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    protected void onCreate(@Nullable Bundle var1) {
        super.onCreate(var1);
        this.setContentView(R.layout.adbix_activity_normal_web);
        this.webView = findViewById(R.id.adbix_webView);
        this.progressBar = findViewById(R.id.adbix_library_pb_progress);
        WebSettings var3;
        WebSettings webSettings = var3 = this.webView.getSettings();
        this.webView.removeJavascriptInterface("searchBoxJavaBridge_");
        this.webView.removeJavascriptInterface("accessibility");
        this.webView.removeJavascriptInterface("accessibilityTraversal");
        webSettings.setSavePassword(false);
        webSettings.setAllowFileAccess(false);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadsImagesAutomatically(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setDatabaseEnabled(true);
        webSettings.setGeolocationEnabled(true);
        this.webView.clearHistory();
        this.webView.clearFormData();
        this.webView.clearCache(true);
        this.webView.getSettings().setDisplayZoomControls(false);
        this.webView.getSettings().setSupportMultipleWindows(true);
        if (VERSION.SDK_INT >= 21) {
            this.webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }

        if (VERSION.SDK_INT >= 23) {
            var3.setOffscreenPreRaster(false);
        }

        this.webView.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView var1, String var2) {
                super.onPageFinished(var1, var2);
            }

            public void onReceivedError(WebView var1, int var2, String var3, String var4) {
            }

            public boolean shouldOverrideUrlLoading(WebView var1, String url1) {
                if (url1.startsWith("tbopen://")) {
                    ShopAppUtil.openTaoBaoApp(WebViewActivity.this, "", url1);
                    return true;
                }

                var1.loadUrl(url1);
                return true;

            }
        });
        this.webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView webView, int newProgress) {
                super.onProgressChanged(webView, newProgress);
                WebViewActivity.this.progressBar.setProgress(newProgress);
                ProgressBar progressBar = WebViewActivity.this.progressBar;
                if (newProgress == 100) {
                    progressBar.setVisibility(View.GONE);
                } else {
                    progressBar.setVisibility(View.VISIBLE);
                }


            }
        });
        Intent var4;
        if ((var4 = this.getIntent()) == null) {
            this.finish();
        } else {
            if (!TextUtils.isEmpty(var4.getStringExtra("KEY_WEB_URL"))) {
                this.webView.loadUrl(var4.getStringExtra("KEY_WEB_URL"));
            } else if (!TextUtils.isEmpty(var4.getStringExtra("KEY_WEB_HTML"))) {
                String var2 = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"/><style type=\"text/css\"></style>    <body>       <p style='font-size: 18px; word-wrap: break-word; color: #555555'>" + var4.getStringExtra("KEY_WEB_HTML") + "</p>    </body></html>";
                this.webView.loadData(var2, "text/html", "UTF-8");
            } else {
                this.finish();
            }

            String var5 = var4.getStringExtra("KEY_WEB_TITLE");
            ((TextView) this.findViewById(R.id.adbix_library_title)).setText(var5);
            this.findViewById(R.id.adbix_library_backlayout).setOnClickListener(new CusClickListener() {
                public void onSingleClick(View var1) {
                    WebViewActivity.this.finish();
                }
            });
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        releaseWebView(webView);
        this.webView = null;
    }

    private void releaseWebView(WebView webView) {
        if (webView != null) {
            Exception exception;
            ViewParent parent = null;
            try {
                parent = webView.getParent();
            } catch (Exception e) {
                exception = e;
            }

            if (parent != null) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeAllViews();
                }
            }

            try {
                webView.setVisibility(View.GONE);
                webView.clearHistory();
                webView.clearView();
                webView.removeAllViews();
                webView.setWebViewClient(null);
                webView.setWebChromeClient(null);
                webView.destroy();
                return;
            } catch (Exception e) {
                exception = e;
            }
            exception.printStackTrace();
        }
    }

}
